Skip to content

refactor(api): use Sequence for read-only collection parameters#139

Merged
seanbrar merged 1 commit intomainfrom
refactor/sequence-type-annotations
Mar 5, 2026
Merged

refactor(api): use Sequence for read-only collection parameters#139
seanbrar merged 1 commit intomainfrom
refactor/sequence-type-annotations

Conversation

@seanbrar
Copy link
Owner

@seanbrar seanbrar commented Mar 5, 2026

Summary

Replace concrete list[...] | tuple[...] unions with collections.abc.Sequence in public API signatures (run_many, create_cache, normalize_request, create_cache_impl). These functions only iterate - Sequence accurately reflects the contract and eliminates mypy invariance errors for callers passing list[str] where list[str | None] was expected.

Related issue

None

Test plan

No new tests - non-behavioral change. Type annotations only; no runtime code altered.

  • just check passes (lint + mypy strict + 176 tests)
  • Verified empirically that mypy rejects list[str]list[str | None] but accepts list[str]Sequence[str | None]

Replace concrete `list[...] | tuple[...]` unions with
`collections.abc.Sequence` in the public API signatures for `run_many`,
`create_cache`, `normalize_request`, and `create_cache_impl`.

These functions only iterate over their inputs (never mutate), so
`Sequence` accurately reflects the contract.  Because `Sequence` is
covariant, this eliminates mypy invariance errors when callers pass a
`list[str]` where `list[str | None]` was expected — a paper cut that
previously required callers to use tuples or widen their annotations.

All imports are typing-only (behind `TYPE_CHECKING`).  No runtime
behavior change.
@codecov
Copy link

codecov bot commented Mar 5, 2026

Codecov Report

❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/pollux/cache.py 0.00% 1 Missing ⚠️
src/pollux/request.py 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@seanbrar seanbrar merged commit a54b3a1 into main Mar 5, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant